package com.example.sunsg.okhttptest.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.View;

import com.breadtrip.R;
import com.example.sunsg.okhttptest.bean.Book;
import com.example.sunsg.okhttptest.cuseomannotation.LayoutAnnotation;
import com.example.sunsg.okhttptest.util.AnnotationUtil;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.lang.reflect.Method;

@LayoutAnnotation(R.layout.activity_annotation)
public class AnnotationActivity extends AppCompatActivity {

    public static void launch(Context context){
        context.startActivity(new Intent(context,AnnotationActivity.class));
    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AnnotationUtil.injectionLayout(this);
//        setContentView(R.layout.activity_annotation);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });

        annotationMethoe(this);
        Book book = new Book("name",2);
        Class<?> bookClazz = book.getClass();
        bookClazz.getName();
    }

    public void helloEvent(Book book,int x){

    }

    public void hasExection(){
        File file = new File("");
        try {
            InputStream inputStream = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }


    private void annotationMethoe(Object object){
        Class<?> clazz = object.getClass();
        Method[] methods = clazz.getDeclaredMethods();
        for (Method method : methods){
            int modify = method.getModifiers();
            String methoeName = method.getName();
            Class<?>[] paramsTypes = method.getParameterTypes();
            for (int i = 0; i < paramsTypes.length; i++) {
                Class<?> paramsType = paramsTypes[i];
                Class<?> parmasClass = paramsType.getClass();
                String paramsName = paramsType.getName();
                String simpleName = paramsType.getSimpleName();
                Log.i("test",i+" parmas   name = "+paramsName +" simname = "+simpleName);
            }

            Class<?> evec[] = method.getExceptionTypes();
            for (int j = 0 ; j < evec.length;j++){
                Log.i("test"," evec  # "+ j +evec[j]);
            }
        }
    }


}
